Skip to content

fix: return None for macro rule with missing param kind instead of panicking#9809

Merged
orizi merged 1 commit intomainfrom
orizi/03-31-fix_macro_rule_missing_param_kind
Apr 1, 2026
Merged

fix: return None for macro rule with missing param kind instead of panicking#9809
orizi merged 1 commit intomainfrom
orizi/03-31-fix_macro_rule_missing_param_kind

Conversation

@orizi
Copy link
Copy Markdown
Collaborator

@orizi orizi commented Mar 31, 2026

Summary

Fixed handling of declarative macro parameters that are missing kind specifiers by returning None instead of panicking with unreachable!(), and added a test case to verify proper error reporting for this scenario.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

The code was using unreachable!() for a case that can actually occur when macro parameters are missing kind specifiers, causing the compiler to panic instead of gracefully handling the error and providing proper diagnostics to the user.


What was the behavior or documentation before?

When a declarative macro parameter was missing a kind specifier (e.g., ($x) instead of ($x:expr)), the compiler would panic with an "unreachable" error during macro rule matching.


What is the behavior or documentation after?

The compiler now gracefully handles missing kind specifiers by returning None from the matching function, allowing proper error diagnostics to be generated (E1010: "Macro parameter must have a kind" and E2158: "No matching rule found in inline macro").


Related issue or discussion (if any)

Fixes #9797


Additional context

The test case demonstrates that the compiler now properly reports two errors: one for the missing kind specifier in the macro definition, and another for the failed macro invocation due to no matching rules.


Note

Low Risk
Small, localized change that only affects invalid macro patterns by turning a panic into a normal match failure; low chance of impacting valid macro expansion.

Overview
Fixes declarative macro rule matching to gracefully fail when a macro parameter is missing its kind specifier: is_macro_rule_match_ex now returns None instead of panicking via unreachable!().

Adds a semantic test case covering macro m { ($x) => ... } to ensure the compiler reports the expected diagnostics (missing kind + no matching rule) rather than crashing.

Written by Cursor Bugbot for commit a9de8c0. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link
Copy Markdown

This change is Reviewable

Copy link
Copy Markdown
Collaborator Author

orizi commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

@eytan-starkware eytan-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Copy link
Copy Markdown
Collaborator

@TomerStarkware TomerStarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

@TomerStarkware made 1 comment.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi orizi force-pushed the orizi/03-31-fix_missing_return_type_in_loop_body branch from b495f1a to e43c38a Compare April 1, 2026 09:05
@orizi orizi force-pushed the orizi/03-31-fix_macro_rule_missing_param_kind branch from dbb21ea to 95108b3 Compare April 1, 2026 09:05
@orizi orizi changed the base branch from orizi/03-31-fix_missing_return_type_in_loop_body to graphite-base/9809 April 1, 2026 09:15
@orizi orizi force-pushed the orizi/03-31-fix_macro_rule_missing_param_kind branch from 95108b3 to a9de8c0 Compare April 1, 2026 09:15
@orizi orizi force-pushed the graphite-base/9809 branch from e43c38a to 8dd8779 Compare April 1, 2026 09:15
@orizi orizi changed the base branch from graphite-base/9809 to main April 1, 2026 09:15
@orizi orizi enabled auto-merge April 1, 2026 09:15
Copy link
Copy Markdown
Collaborator Author

@orizi orizi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orizi reviewed 1 file and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on orizi).

@orizi orizi added this pull request to the merge queue Apr 1, 2026
Merged via the queue into main with commit 8c8cbaf Apr 1, 2026
105 checks passed
@orizi orizi deleted the orizi/03-31-fix_macro_rule_missing_param_kind branch April 1, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Compiler panic in semantic pass: unreachable!() in is_macro_rule_match_ex for macro param without kind

4 participants